{extend name="common/base"/}
<!-- 主体 -->
{block name="body"}

<div class="p-3">

    <table class="layui-hide" id="user_level" lay-filter="user_level"></table>
</div>

<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <span class="layui-btn layui-btn-sm" lay-event="add" data-title="添加企业类型">+ 添加企业类型</span>
    </div>
</script>

<script type="text/html" id="barDemo">
    <div class="layui-btn-group">
        <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
        	<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
    </div>
</script>
<script type="text/html" id="image">
    <img src="{{d.image}}" width="30" height="30" lay-event="image"/>
</script>
<script type="text/html" id="imagesArr">
    {{# if(d.images != ''){ }}
    {{# layui.each(d.images, function(index, item){ }}
    <img src="{{item}}" width="30" height="30"  lay-event="image"/>
    {{# }); }}
    {{# }else{}}
    暂无图片
    {{#}}}
</script>
{/block}
<!-- /主体 -->

<!-- 脚本 -->
{block name="script"}
<script>
    const moduleInit = ['tool'];
    function gouguInit() {
        var table = layui.table,tool = layui.tool, form = layui.form;
        layui.pageTable = table.render({
            elem: '#user_level',
            title: '企业类型列表',
            toolbar: '#toolbarDemo',
            url: '/admin/qi_cate/datalist',
            page: true,
            limit: 20,
            lineStyle:'height:auto',
            cellMinWidth: 60,
            cols: [
                [
                    {
                        // fixed: 'left',
                        field: 'id',
                        title: '编号',
                        align: 'center',
                        width: 80
                    },{
                    field: 'title',
                    title: '名称',
                    width: 220
                },
                    {
                        field: 'right',
                        title: '操作',
                        toolbar: '#barDemo',
                        width: 136,
                        align: 'center'
                    }
                ]
            ]
        });

        //监听表头工具栏事件
        table.on('toolbar(user_level)', function(obj){
            if (obj.event === 'add') {
                tool.side("/admin/qi_cate/add");
                return false;
            }
        });

        //监听表格行工具事件
        table.on('tool(user_level)', function(obj) {
            var data = obj.data;
            if (obj.event === 'read') {
                tool.side('/admin/qi_cate/read?id='+obj.data.id);
            }
            else if (obj.event === 'edit') {
                tool.side('/admin/qi_cate/edit?id='+obj.data.id);
            }
            else if (obj.event === 'del') {
                layer.confirm('确定要删除该记录吗?', {
                    icon: 3,
                    title: '提示'
                }, function(index) {
                    let callback = function (e) {
                        layer.msg(e.msg);
                        if (e.code == 0) {
                            obj.del();
                        }
                    }
                    tool.delete("/admin/qi_cate/del", { id: data.id }, callback);
                    layer.close(index);
                });
            }
            if(obj.event === 'image')
            {
                var src = $(this).attr('src');
                // 在此处输入 layer 的任意代码
                layer.open({
                    type: 1, // page 层类型
                    area: ['500px', '500px'],
                    title: '',
                    shade: 0.6, // 遮罩透明度
                    shadeClose: true, // 点击遮罩区域，关闭弹层
                    maxmin: true, // 允许全屏最小化
                    anim: 0, // 0-6 的动画形式，-1 不开启
                    content: "<img src="+src+" style='width: 100%;'>"
                });
            }
            return false;
        });

        //监听搜索提交
        form.on('submit(searchform)', function(data) {
            layui.pageTable.reload({
                where: {
                    keywords: data.field.keywords
                },
                page: {
                    curr: 1
                }
            });
            return false;
        });
    }
</script>
{/block}
<!-- /脚本 -->